﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace TraceThisItem.Domain
{
	public class StatusNode
	{
		#region Properties

		public int Id { get; set; }
		public string Name { get; set; }
		public int WorkflowId { get; set; }

		#endregion

		#region Navigation properties

		//public virtual StatusType StatusType { get; set; }
		public virtual ICollection<StatusNode> NextStatusNodes { get; set; }
		public virtual Workflow Workflow { get; set; }

		#endregion

		public void AddNextStatus(StatusNode statusNode)
		{
			this.NextStatusNodes.Add(statusNode);
		}

		public bool RemoveNextStatus(StatusNode statusNode)
		{
			if (this.NextStatusNodes.Count > 1)
			{
				this.NextStatusNodes.Remove(statusNode);
				return true;
			}
			return false;
		}

		#region Constructor
		public StatusNode(string name)
		{
			this.Name = name;
			this.NextStatusNodes = new List<StatusNode>();
		}

		public StatusNode()
			: this("Nuevo")
		{

		} 
		#endregion

		#region Display Properties

		public string NextStatusNodesNames
		{
			get
			{				
				return string.Join(", ",this.NextStatusNodes.Select(n => n.Name).ToArray());			
			}
		}
		#endregion

		// override object.Equals
		public override bool Equals(object obj)
		{
			if (obj == null || GetType() != obj.GetType())
			{
				return false;
			}

			return this.Id == (obj as StatusNode).Id;
		}

		// override object.GetHashCode
		public override int GetHashCode()
		{
			return this.Id.GetHashCode();
		}
	}
}
